//
//  YXAmendMessageViewController.m
//  跑跑快销
//
//  Created by 杨潇 on 14-4-30.
//  Copyright (c) 2014年 ylife. All rights reserved.
//

#import "YXAmendMessageViewController.h"

@interface YXAmendMessageViewController ()

@end

@implementation YXAmendMessageViewController
@synthesize mutableInfoDic,amendType,tableView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.translucent = NO;
    _amendMessageView = [[YXAmendMessageView alloc] init];
    self.view = _amendMessageView;
    
    [_amendMessageView.amendBtn addTarget:self action:@selector(touchAmendBtn) forControlEvents:UIControlEventTouchUpInside];
}

- (void)touchAmendBtn
{
    [self.view endEditing:YES];
    [self sendAmendMessageRequestWithType:amendType parameter:_amendMessageView.amendTextVi.text];
}

- (void)sendAmendMessageRequestWithType:(NSString *)type parameter:(NSString *)parameter
{
    YXWindowInfo * windowInfo = [YXWindowInfo sharedWindowInfo];
    [NSURLConnection sendRequestWithHeadStr:windowInfo.requestUrlStr headValue:[windowInfo.userInfoDic objectForKey:@"token"] serviceToken:nil text:[NSDictionary dictionaryWithObjectsAndKeys:@"updateUserInfo",@"type",type,@"editType",parameter,@"parameter",[[windowInfo.userInfoDic objectForKey:@"userInfo"] objectForKey:@"AccountID"],@"userId", nil] dataBlock:^(NSDictionary *dic) {
        NSString * resultCode = [dic objectForKey:@"resultCode"];
        if ([resultCode isEqualToString:@"0"]) {
            switch ([amendType intValue]) {
                case 0:
                {
                    [self.mutableInfoDic setObject:_amendMessageView.amendTextVi.text forKey:@"AccountName"];
                }
                    break;
                case 5:
                {
                    [self.mutableInfoDic setObject:_amendMessageView.amendTextVi.text forKey:@"AccountRemark"];
                }
                    break;
                    
                default:
                    break;
            }
            [[YXWindowAlertView sharedWindowAlert] showLableWithTitle:@"修改成功"];
            [self.tableView reloadData];
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            NSLog(@"修改个人信息参数错误。");
        }
    }];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
